package com.detrum.sportcamera.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.detrum.bean.ParamsItem;
import com.detrum.sportcamera.R;

import java.util.List;

/**
 * Created by abc on 2018/2/9.
 */

public class WBAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater layoutInflater;
    private List<ParamsItem>list_s;
    private int flag;

    public WBAdapter(Context context, List<ParamsItem>list_s, int flag) {
        this.context = context;
        this.list_s = list_s;
        this.flag = flag;
        layoutInflater = LayoutInflater.from(context);
    }

    public void setPosition(int flag){
        this.flag = flag;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list_s==null?0:list_s.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ParamsHolder holder;
        if(convertView==null){
            convertView = layoutInflater.inflate(R.layout.params_item,parent,false);
            holder = new ParamsHolder();
            holder.icon = convertView.findViewById(R.id.icon);
            holder.name = convertView.findViewById(R.id.name);
            holder.select = convertView.findViewById(R.id.select);
            convertView.setTag(holder);
        }else{
            holder = (ParamsHolder) convertView.getTag();
        }
        holder.icon.setImageResource(list_s.get(position).getIcon());
        holder.name.setText(list_s.get(position).getName());
        if(position == flag){
            holder.select.setImageResource(R.mipmap.select_2);
        }else{
            holder.select.setImageResource(R.mipmap.select_1);
        }
        return convertView;
    }

    class ParamsHolder{
        ImageView icon,select;
        TextView name;
    }
}
